package org.cmroot.certmaster.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import org.cmroot.certmaster.shared.PKIServiceException;
import org.cmroot.certmaster.shared.dto.Pkcs10DTO;
import org.cmroot.certmaster.shared.dto.X509DTO;
import org.cmroot.certmaster.shared.dto.ext.Pkcs10ExtDTO;
import org.cmroot.certmaster.shared.dto.ext.X509ExtDTO;

import java.util.List;

@RemoteServiceRelativePath("certmasterService")
public interface GWTClientService extends RemoteService {
    // Sample interface method of remote interface

    void newRequest(String request) throws PKIServiceException;
    void removePKCS(String clazz, Long id) throws PKIServiceException;
    List<Pkcs10DTO> getRequests() throws PKIServiceException;
    List<X509DTO> getTree() throws PKIServiceException;
    List<X509DTO> getX509Children(Long parent_id) throws PKIServiceException;
    X509DTO getX509(Long id) throws PKIServiceException;
    List<X509DTO> getCA() throws PKIServiceException;
    X509ExtDTO getExtX509(Long id) throws PKIServiceException;
    Pkcs10ExtDTO getExtPkcs10(Long id) throws PKIServiceException;
    List<X509DTO> importChain(String text) throws PKIServiceException;

    /**
     * Utility/Convenience class.
     * Use GWTClientService.App.getInstance() to access static instance of certmasterServiceAsync
     */
    public static class App {
        private static GWTClientServiceAsync ourInstance = GWT.create(GWTClientService.class);

        public static synchronized GWTClientServiceAsync getInstance() {
            return ourInstance;
        }
    }
}
